package com.aboo.design.bridge;

/**
 * @author louan
 * @version 1.0
 * @description: 桥梁模式
 * 将抽象部分与实现部分分离，使它们都可以独立的变化。
 * @date 2024/2/6
 */
public class BridgePattern {
    public static void main(String[] args) {
        Product product = new TvProduct();
        Factory factory = new FuShiKangFactory(product);
        factory.doSomething();

        System.out.println("========================================");

        product = new RadioProduct();
        factory = new FuShiKangFactory(product);
        factory.doSomething();
    }
}

interface Product {
    void shape();
    void color();
}

class TvProduct implements Product {

    @Override
    public void shape() {
        System.out.println("给TV塑形");
    }

    @Override
    public void color() {
        System.out.println("给TV着色");
    }
}

class RadioProduct implements Product {

    @Override
    public void shape() {
        System.out.println("给Radio塑形");
    }

    @Override
    public void color() {
        System.out.println("给Radio着色");
    }
}

abstract class Factory {
    private Product product;

    public Factory(Product product) {
        this.product = product;
    }

    void doSomething() {
        product.shape();
    };

    public Product getProduct() {
        return product;
    }
}

class FuShiKangFactory extends Factory {

    public FuShiKangFactory(Product product) {
        super(product);
    }

    @Override
    void doSomething() {
        super.doSomething();
        System.out.println("我还可以额外做下面的事情");
        getProduct().color();
    }
}